package com.example.springboot.controller;

import com.example.springboot.bean.Employee;
import com.example.springboot.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/10/9 22:02
 */
@RestController
public class EmpController {
    @Autowired
    private EmployeeService employeeService;

    @GetMapping("/emp/{id}")
    public Employee getById(@PathVariable("id") Integer id) {
        return employeeService.getEmp(id);
    }

    @GetMapping("/emp")
    public Employee update(Employee employee) {
        return employeeService.updateEmp(employee);
    }

    @DeleteMapping("/delete")
    public void delete(Integer id) {
        employeeService.deleteEmp(id);
    }
    @GetMapping("/emp/lastname/{name}")
    public Employee getByLastName(@PathVariable("name") String name){
        return employeeService.getEmpByLastName(name);
    }
}
